﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;

namespace Catering.Catering_Page.Caipin
{
    public partial class Caipin_Manage : System.Web.UI.Page
    {
        #region 王泽伟部分
        #region 公共变量和公共方法
        Catering_Rules.T_Dish _BllDish = new Catering_Rules.T_Dish();
        Catering_Model.E_Dish Mdh = new Catering_Model.E_Dish();
        Catering.View_Operaction.Caipin_Manage_Operaction cmo = new View_Operaction.Caipin_Manage_Operaction();
        Catering_Rules.T_DishInfo _BllDishInfo = new Catering_Rules.T_DishInfo();
        Catering_Model.E_DishInfo _ModelDishInfo;

        Catering_Rules.DishNutrien CRDN = new Catering_Rules.DishNutrien();

        List<Catering_Model.DishNutrien> mdnlist = new List<Catering_Model.DishNutrien>();
        public void DishNews(int ID, string Name, string Lblname)
        {
            Catering_Model.DishNutrien CMDN = new Catering_Model.DishNutrien();//元
            CMDN.Dishid = ID;                                                  //素
            CMDN.Content = Lblname;                                            //表
            CMDN.element_name = Name;
            CRDN.Add(CMDN);
            mdnlist.Add(CMDN);
        }
        /// <summary>
        /// 新写的
        /// </summary>
        public void Exec()
        {
            CRDN.TransAdd(mdnlist);
            CRDN.ExecTrans();
        }
        Catering_Rules.T_RawMaterials crrm = new Catering_Rules.T_RawMaterials();
        Catering_Rules.DishType crdt = new Catering_Rules.DishType();
        Catering_Model.RAEInfo CMR = new Catering_Model.RAEInfo();
        #endregion
        #region 菜品设置的保存
        protected void bt_zengjia_Click(object sender, ImageClickEventArgs e)
        {
            #region 菜信息插入
            Mdh.Name = Txt_caiming.Text.Trim();
            Mdh.Characteristic = Txt_tedian.Text.Trim();
            Mdh.FMID = Convert.ToInt32(Dr_library.Text);
            Mdh.DTID = Convert.ToInt32(Dr_DishType.Text);
            Mdh.Method = Txt_zuofa.Text.Trim();
            //韦琪添加 20120316
            Mdh.Back = TxtBack.Text.Trim();
            int DDID = _BllDish.Addd(Mdh);
            Response.Write(DDID);
            #endregion
            // 插入菜品食物信息
            #region 主要膳食营养含量
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["id"] != null)
                    {
                        _ModelDishInfo = new Catering_Model.E_DishInfo();
                        _ModelDishInfo.id = _BllDishInfo.GetMaxId();
                        _ModelDishInfo.DID = DDID;
                        _ModelDishInfo.DName = dt.Rows[i]["Food"].ToString();
                        _ModelDishInfo.RawID = 1;
                        _ModelDishInfo.Re = int.Parse(dt.Rows[i]["re"].ToString());
                        _ModelDishInfo.ZS = dt.Rows[i]["zs"].ToString();
                        _BllDishInfo.Add(_ModelDishInfo);
                    }
                }
            }
            #endregion
            // 插入其他微量元素
            #region 营养成分信息插入

            DishNews(DDID, lbl_reliang.Text, "热量");
            DishNews(DDID, lbl_danbaizhi.Text, "蛋白质");
            DishNews(DDID, lbl_zhifang.Text, "脂肪");
            DishNews(DDID, lbl_tanshuihuahewu.Text, "碳水化合物");
            DishNews(DDID, lbl_weishengsuA.Text, "膳食纤维");
            DishNews(DDID, lbl_danbaizhi.Text, "维生素A");
            DishNews(DDID, lbl_weishengsuB1.Text, "维生素B1");
            DishNews(DDID, lbl_weishengsuB2.Text, "维生素B2");
            DishNews(DDID, lbl_weishengsuC.Text, "维生素C");
            DishNews(DDID, lbl_weishengsuE.Text, "维生素E");
            DishNews(DDID, lbl_shihuangchundangliang.Text, "视黄醇当量");
            DishNews(DDID, lbl_nikesuan.Text, "尼克酸");
            DishNews(DDID, lbl_huluobosu.Text, "胡萝卜素");
            DishNews(DDID, lbl_gai.Text, "钙");
            DishNews(DDID, lbl_ling.Text, "磷");
            DishNews(DDID, lbl_jia.Text, "钾");
            DishNews(DDID, lbl_na.Text, "钠");
            DishNews(DDID, lbl_mei.Text, "镁");
            DishNews(DDID, lbl_tie.Text, "铁");
            DishNews(DDID, lbl_xin.Text, "锌");
            DishNews(DDID, lbl_xi.Text, "硒");
            DishNews(DDID, lbl_tong.Text, "铜");
            DishNews(DDID, lbl_men.Text, "锰");
            DishNews(DDID, lbl_dian.Text, "镁");
            DishNews(DDID, lbl_tie.Text, "碘");
            //新写的
            Exec();
        }
            #endregion
        #endregion
        #region 加载类
        protected void Page_Load(object sender, EventArgs e)
        {
            strTreeview = voc.UIDataBing_RawMaterials();
            zhi = "保存";

            ViewState["id"] = "0";
            ViewState["strRawHtml"] = string.Empty;
            ViewState["strint"] = "0";
            ViewState["strDishHtml"] = string.Empty;
            ViewState["strTableHtml"] = string.Empty;
            ViewState["strTable"] = string.Empty;
            if (!IsPostBack)
            {
                int companyid = 0;
                if (Session["UserID"] != null)
                {
                    string userid = Session["UserID"].ToString();
                    companyid = new Catering_Rules.T_Personnel().GetCompanyIDByPID(Convert.ToInt32(userid));
                }
                voc.TreeViewDataBind_Library(this.DataList_Library);
                voc.TreeViewDataBing_RawMaterials(Tv_RawMaterial);
                voc.TreeViewDataBind_DishTypes(Tv_Dish, "1");
                voc.TreeViewDataBing_RawMaterials(Tv_RawMaterial2);
                voc.DropDownListDataBind_library(Dr_library);
                voc.DropDownListDataBind_Water(DDLShuiFen);
                voc.DropDownListDataBind_Edible(DDLShiBu);
                voc.DropDownListDataBind_RawMaterials(DDLzhongsu);
                voc.DropDownListDataBind_Group(Dr_Operaction, companyid);
                voc.DropDownListDataBind_Class(Dr_Class, Dr_Operaction.Items[0].Value);

                if (Dr_library.Items.Count > 0)
                {
                    voc.DropDownListDataBind_DishTypes(Dr_DishType, Dr_library.Items[0].Value);
                }
                ViewState["strRawHtml"] = cmo.GetRawType();
                ViewState["strDishHtml"] = cmo.GetDishType();
                ViewState["strTable"] = cmo.ShowLibery("1", "1");
            }
        }
        #endregion
        #endregion

        #region 韦琪部分
        View_Operaction_Common voc = new View_Operaction_Common();
        //菜谱库
        public static string strLibrary = string.Empty;
        private static int i = 0;

        public static string strFilePath = string.Empty;
        public static DataTable dt = new Catering_DataSet.RawInfoDataTable();
        public static string zhi;
        public static string strTableHtml = string.Empty;

        public static string strTreeview = string.Empty;
        #endregion

        #region
        /// <summary>
        /// 选择菜谱库
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ButLibrary_Click(object sender, EventArgs e)
        {
            string str = strLibrary;
            voc.TreeViewDataBind_DishTypes(Tv_Dish, strLibrary);

        }

        /// <summary>
        /// 原料树
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Tv_RawMaterial_SelectedNodeChanged(object sender, EventArgs e)
        {
            TreeNode tn = Tv_RawMaterial.SelectedNode;
            Catering_Rules.Species crs = new Catering_Rules.Species();
            Catering_Rules.T_RawMaterial crr = new Catering_Rules.T_RawMaterial();
            Catering_Model.E_RawMaterial cmr = crr.GetModel(Convert.ToInt32(tn.Value));
            Catering_Model.Species cms = crs.GetModel(cmr.RAWZS);
            Catering.View_Operaction.Caipin_Manage_Operaction cmo = new View_Operaction.Caipin_Manage_Operaction();
            string str = tn.Target;


            i = i + 1;
            if (Session["strTableHtml"] == null)
            {
                Session["strTableHtml"] =
                    cmo.GetTableHtml(i, tn.Text, cms.TypeName, tn.Target);
            }
            else
            {
                Session["strTableHtml"] = Session["strTableHtml"].ToString() +
                    cmo.GetTableHtml(i, tn.Text, cms.TypeName, tn.Target);
            }


            cmo.setDataToDataTable(dt, i, tn.Text, cms.TypeName, tn.Target, tn.Value);
            setLableValue(tn.Value);

        }
        public void setLableValue(string strRawID)
        {
            Catering_Rules.ViewOperaction crvo = new Catering_Rules.ViewOperaction();
            int num = 100;
            Catering.View_Operaction.Caipin_Manage_Operaction cmo = new View_Operaction.Caipin_Manage_Operaction();
            DataTable dt = cmo.Nutrient_DataSetToDatatabl();
            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow[] dr_Nutrient = dt.Select("RaWId=" + strRawID);

                reliang = reliang + Convert.ToInt32(dr_Nutrient[0][1]) * num;
                this.lbl_reliang.Text = reliang.ToString();

                danbaizhi = danbaizhi + Convert.ToInt32(dr_Nutrient[0][2]) * num;
                this.lbl_danbaizhi.Text = danbaizhi.ToString();

                zhifang = zhifang + Convert.ToInt32(dr_Nutrient[0][3]) * num;
                this.lbl_zhifang.Text = zhifang.ToString();

                tanshuihuahewu = tanshuihuahewu + Convert.ToInt32(dr_Nutrient[0][4]) * num;
                this.lbl_tanshuihuahewu.Text = tanshuihuahewu.ToString();

                shanshixianwei = shanshixianwei + Convert.ToInt32(dr_Nutrient[0][5]) * num;
                this.lbl_shanshixianwei.Text = shanshixianwei.ToString();

                weishengsuA = weishengsuA + Convert.ToInt32(dr_Nutrient[0][6]) * num;
                this.lbl_weishengsuA.Text = weishengsuA.ToString();

                weishengsuB1 = weishengsuB1 + Convert.ToInt32(dr_Nutrient[0][7]) * num;
                this.lbl_weishengsuB1.Text = weishengsuB1.ToString();

                weishengsuB2 = weishengsuB2 + Convert.ToInt32(dr_Nutrient[0][8]) * num;
                this.lbl_weishengsuB2.Text = weishengsuB2.ToString();

                weishengsuC = weishengsuC + Convert.ToInt32(dr_Nutrient[0][9]) * num;
                this.lbl_weishengsuC.Text = weishengsuC.ToString();

                weishengsuE = weishengsuE + Convert.ToInt32(dr_Nutrient[0][10]) * num;
                this.lbl_weishengsuE.Text = weishengsuE.ToString();

                shihuangchundangliang = shihuangchundangliang + Convert.ToInt32(dr_Nutrient[0][11]) * num;
                this.lbl_shihuangchundangliang.Text = shihuangchundangliang.ToString();

                nikesuan = nikesuan + Convert.ToInt32(dr_Nutrient[0][12]) * num;
                this.lbl_nikesuan.Text = nikesuan.ToString();

                huluobosu = huluobosu + Convert.ToInt32(dr_Nutrient[0][13]) * num;
                this.lbl_huluobosu.Text = huluobosu.ToString();

                gai = gai + Convert.ToInt32(dr_Nutrient[0][14]) * num;
                this.lbl_gai.Text = gai.ToString();

                ling = ling + Convert.ToInt32(dr_Nutrient[0][15]) * num;
                this.lbl_ling.Text = ling.ToString();

                jia = jia + Convert.ToInt32(dr_Nutrient[0][16]) * num;
                this.lbl_jia.Text = jia.ToString();

                na = na + Convert.ToInt32(dr_Nutrient[0][17]) * num;
                this.lbl_na.Text = na.ToString();

                mei = mei + Convert.ToInt32(dr_Nutrient[0][18]) * num;
                this.lbl_mei.Text = mei.ToString();

                tie = tie + Convert.ToInt32(dr_Nutrient[0][19]) * num;
                this.lbl_tie.Text = tie.ToString();

                xin = xin + Convert.ToInt32(dr_Nutrient[0][20]) * num;
                this.lbl_xin.Text = xin.ToString();

                xi = xi + Convert.ToInt32(dr_Nutrient[0][21]) * num;
                this.lbl_xi.Text = xi.ToString();

                tong = tong + Convert.ToInt32(dr_Nutrient[0][22]) * num;
                this.lbl_tong.Text = tong.ToString();

                men = men + Convert.ToInt32(dr_Nutrient[0][23]) * num;
                this.lbl_men.Text = men.ToString();

                dian = dian + Convert.ToInt32(dr_Nutrient[0][24]) * num;
                this.lbl_dian.Text = dian.ToString();

            }



        }
        #region 存放微量元素
        static Int32 reliang = 0;
        static Int32 danbaizhi = 0;
        static Int32 zhifang = 0;
        static Int32 tanshuihuahewu = 0;
        static Int32 shanshixianwei = 0;
        static Int32 weishengsuA = 0;
        static Int32 weishengsuB1 = 0;
        static Int32 weishengsuB2 = 0;
        static Int32 weishengsuC = 0;
        static Int32 weishengsuE = 0;
        static Int32 shihuangchundangliang = 0;
        static Int32 nikesuan = 0;
        static Int32 huluobosu = 0;

        static Int32 gai = 0;
        static Int32 ling = 0;
        static Int32 jia = 0;
        static Int32 na = 0;
        static Int32 mei = 0;
        static Int32 tie = 0;
        static Int32 xin = 0;
        static Int32 xi = 0;
        static Int32 tong = 0;
        static Int32 men = 0;
        static Int32 dian = 0;
        #endregion

        protected void ButSet_Raw_Click(object sender, EventArgs e)
        {
            if (this.RawSet.Value.Length > 0)
            {
                string[] str = this.RawSet.Value.Split(new char[] { ',' });
                string strtest = "value='100' ID='Txt_jinghanliang" + str[2] + "'";
                string strnew = "value='" + str[1] + "' ID='Txt_jinghanliang" + str[2] + "'";
                if (Session["strTableHtml"].ToString().IndexOf(strtest) > -1)
                {
                    Session["strTableHtml"] = Session["strTableHtml"].ToString().Replace(strtest, strnew);
                }

                //   setLableValue(str[0],str[1]);
            }
        }
        #region
        //public void setLableValue(string strName,string Number)
        //{
        //    Catering_Rules.ViewOperaction crvo = new Catering_Rules.ViewOperaction();
        //    int num = Convert.ToInt32(Number);


        //    DataTable dt = Nutrient_DataSetToDatatabl();
        //    if (dt != null && dt.Rows.Count > 0)
        //    {
        //        DataRow[] dr_Nutrient = dt.Select("RawName='" + strName + "'");
        //        if (reliang>0)
        //        {


        //            if (Convert.ToInt32(Number) - 100 < 1)
        //            {
        //                num = 100 - num;
        //                reliang = reliang - Convert.ToInt32(dr_Nutrient[0][1]) * num;
        //                lbl_reliang.Text = reliang.ToString();

        //                danbaizhi = danbaizhi - Convert.ToInt32(dr_Nutrient[0][2]) * num;
        //                lbl_danbaizhi.Text = danbaizhi.ToString();

        //                zhifang = zhifang - Convert.ToInt32(dr_Nutrient[0][3]) * num;
        //                this.lbl_zhifang.Text = zhifang.ToString();

        //                tanshuihuahewu = tanshuihuahewu - Convert.ToInt32(dr_Nutrient[0][4]) * num;
        //                this.lbl_tanshuihuahewu.Text = tanshuihuahewu.ToString();

        //                shanshixianwei = shanshixianwei - Convert.ToInt32(dr_Nutrient[0][5]) * num;
        //                this.lbl_shanshixianwei.Text = shanshixianwei.ToString();

        //                weishengsuA = weishengsuA - Convert.ToInt32(dr_Nutrient[0][6]) * num;
        //                this.lbl_weishengsuA.Text = weishengsuA.ToString();

        //                weishengsuB1 = weishengsuB1 - Convert.ToInt32(dr_Nutrient[0][7]) * num;
        //                this.lbl_weishengsuB1.Text = weishengsuB1.ToString();

        //                weishengsuB2 = weishengsuB2 + Convert.ToInt32(dr_Nutrient[0][8]) * num;
        //                this.lbl_weishengsuB2.Text = weishengsuB2.ToString();

        //                weishengsuC = weishengsuC - Convert.ToInt32(dr_Nutrient[0][9]) * num;
        //                this.lbl_weishengsuC.Text = weishengsuC.ToString();

        //                weishengsuE = weishengsuE - Convert.ToInt32(dr_Nutrient[0][10]) * num;
        //                this.lbl_weishengsuE.Text = weishengsuE.ToString();

        //                shihuangchundangliang = shihuangchundangliang - Convert.ToInt32(dr_Nutrient[0][11]) * num;
        //                this.lbl_shihuangchundangliang.Text = shihuangchundangliang.ToString();

        //                nikesuan = nikesuan - Convert.ToInt32(dr_Nutrient[0][12]) * num;
        //                this.lbl_nikesuan.Text = nikesuan.ToString();

        //                huluobosu = huluobosu - Convert.ToInt32(dr_Nutrient[0][13]) * num;
        //                this.lbl_huluobosu.Text = huluobosu.ToString();

        //                gai = gai - Convert.ToInt32(dr_Nutrient[0][14]) * num;
        //                this.lbl_gai.Text = gai.ToString();

        //                ling = ling - Convert.ToInt32(dr_Nutrient[0][15]) * num;
        //                this.lbl_ling.Text = ling.ToString();

        //                jia = jia - Convert.ToInt32(dr_Nutrient[0][16]) * num;
        //                this.lbl_jia.Text = jia.ToString();

        //                na = na - Convert.ToInt32(dr_Nutrient[0][17]) * num;
        //                this.lbl_na.Text = na.ToString();

        //                mei = mei - Convert.ToInt32(dr_Nutrient[0][18]) * num;
        //                this.lbl_mei.Text = mei.ToString();

        //                tie = tie - Convert.ToInt32(dr_Nutrient[0][19]) * num;
        //                this.lbl_tie.Text = tie.ToString();

        //                xin = xin - Convert.ToInt32(dr_Nutrient[0][20]) * num;
        //                this.lbl_xin.Text = xin.ToString();

        //                xi = xi - Convert.ToInt32(dr_Nutrient[0][21]) * num;
        //                this.lbl_xi.Text = xi.ToString();

        //                tong = tong - Convert.ToInt32(dr_Nutrient[0][22]) * num;
        //                this.lbl_tong.Text = tong.ToString();

        //                men = men - Convert.ToInt32(dr_Nutrient[0][23]) * num;
        //                this.lbl_men.Text = men.ToString();

        //                dian = dian - Convert.ToInt32(dr_Nutrient[0][24]) * num;
        //                this.lbl_dian.Text = dian.ToString();
        //            }
        //            else
        //            {
        //                num = num - 100;
        //                reliang = Convert.ToInt32(this.lbl_reliang.Text) + Convert.ToInt32(dr_Nutrient[0][1]) * num;
        //                this.lbl_reliang.Text = reliang.ToString();

        //                danbaizhi = Convert.ToInt32(this.lbl_danbaizhi.Text) + Convert.ToInt32(dr_Nutrient[0][2]) * num;
        //                this.lbl_danbaizhi.Text = danbaizhi.ToString();

        //                zhifang = Convert.ToInt32(this.lbl_zhifang.Text) + Convert.ToInt32(dr_Nutrient[0][3]) * num;
        //                this.lbl_zhifang.Text = zhifang.ToString();

        //                tanshuihuahewu = Convert.ToInt32(this.lbl_tanshuihuahewu.Text) + Convert.ToInt32(dr_Nutrient[0][4]) * num;
        //                this.lbl_tanshuihuahewu.Text = tanshuihuahewu.ToString();

        //                shanshixianwei = Convert.ToInt32(this.lbl_shanshixianwei.Text) + Convert.ToInt32(dr_Nutrient[0][5]) * num;
        //                this.lbl_shanshixianwei.Text = shanshixianwei.ToString();

        //                weishengsuA = Convert.ToInt32(this.lbl_weishengsuA.Text) + Convert.ToInt32(dr_Nutrient[0][6]) * num;
        //                this.lbl_weishengsuA.Text = weishengsuA.ToString();

        //                weishengsuB1 = Convert.ToInt32(this.lbl_weishengsuB1.Text) + Convert.ToInt32(dr_Nutrient[0][7]) * num;
        //                this.lbl_weishengsuB1.Text = weishengsuB1.ToString();

        //                weishengsuB2 = Convert.ToInt32(this.lbl_weishengsuB2.Text) + Convert.ToInt32(dr_Nutrient[0][8]) * num;
        //                this.lbl_weishengsuB2.Text = weishengsuB2.ToString();

        //                weishengsuC = Convert.ToInt32(this.lbl_weishengsuC.Text) + Convert.ToInt32(dr_Nutrient[0][9]) * num;
        //                this.lbl_weishengsuC.Text = weishengsuC.ToString();

        //                weishengsuE = Convert.ToInt32(this.lbl_weishengsuE.Text) + Convert.ToInt32(dr_Nutrient[0][10]) * num;
        //                this.lbl_weishengsuE.Text = weishengsuE.ToString();

        //                shihuangchundangliang = Convert.ToInt32(this.lbl_shihuangchundangliang.Text) + Convert.ToInt32(dr_Nutrient[0][11]) * num;
        //                this.lbl_shihuangchundangliang.Text = shihuangchundangliang.ToString();

        //                nikesuan = Convert.ToInt32(this.lbl_nikesuan.Text) + Convert.ToInt32(dr_Nutrient[0][12]) * num;
        //                this.lbl_nikesuan.Text = nikesuan.ToString();

        //                huluobosu = Convert.ToInt32(this.lbl_huluobosu.Text) + Convert.ToInt32(dr_Nutrient[0][13]) * num;
        //                this.lbl_huluobosu.Text = huluobosu.ToString();

        //                gai = Convert.ToInt32(this.lbl_gai.Text) + Convert.ToInt32(dr_Nutrient[0][14]) * num;
        //                this.lbl_gai.Text = gai.ToString();

        //                ling = Convert.ToInt32(this.lbl_ling.Text) + Convert.ToInt32(dr_Nutrient[0][15]) * num;
        //                this.lbl_ling.Text = ling.ToString();

        //                jia = Convert.ToInt32(this.lbl_jia.Text) + Convert.ToInt32(dr_Nutrient[0][16]) * num;
        //                this.lbl_jia.Text = jia.ToString();

        //                na = Convert.ToInt32(this.lbl_na.Text) + Convert.ToInt32(dr_Nutrient[0][17]) * num;
        //                this.lbl_na.Text = na.ToString();

        //                mei = Convert.ToInt32(this.lbl_mei.Text) + Convert.ToInt32(dr_Nutrient[0][18]) * num;
        //                this.lbl_mei.Text = mei.ToString();

        //                tie = Convert.ToInt32(this.lbl_tie.Text) + Convert.ToInt32(dr_Nutrient[0][19]) * num;
        //                this.lbl_tie.Text = tie.ToString();

        //                xin = Convert.ToInt32(this.lbl_xin.Text) + Convert.ToInt32(dr_Nutrient[0][20]) * num;
        //                this.lbl_xin.Text = xin.ToString();

        //                xi = Convert.ToInt32(this.lbl_xi.Text) + Convert.ToInt32(dr_Nutrient[0][21]) * num;
        //                this.lbl_xi.Text = xi.ToString();

        //                tong = Convert.ToInt32(this.lbl_tong.Text) + Convert.ToInt32(dr_Nutrient[0][22]) * num;
        //                this.lbl_tong.Text = tong.ToString();

        //                men = Convert.ToInt32(this.lbl_men.Text) + Convert.ToInt32(dr_Nutrient[0][23]) * num;
        //                this.lbl_men.Text = men.ToString();

        //                dian = Convert.ToInt32(this.lbl_dian.Text) + Convert.ToInt32(dr_Nutrient[0][24]) * num;
        //                this.lbl_dian.Text = dian.ToString();
        //            }
        //        }




        //    }



        //}
        #endregion
        #region 上传图片
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void butUpClose_Click(object sender, EventArgs e)
        {
            ImgUpPoto.ImageUrl = cmo.UpImage(this.File_Upload);
        }

        protected void but_Raw_Close_Click(object sender, EventArgs e)
        {

        }

        #endregion

        #region 清理几界面
        /// <summary>
        /// 清理菜品界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ButClear_Dish_Click(object sender, EventArgs e)
        {
            this.Txt_caiming.Text = "";
            this.Txt_tedian.Text = "";
            this.Txt_zuofa.Text = "";
            Session["strTableHtml"] = null;
            dt.Clear();
            strTableHtml = string.Empty;

            this.lbl_reliang.Text = string.Empty;
            this.lbl_danbaizhi.Text = string.Empty;
            this.lbl_zhifang.Text = string.Empty;
            this.lbl_tanshuihuahewu.Text = string.Empty;
            this.lbl_shanshixianwei.Text = string.Empty;
            this.lbl_weishengsuA.Text = string.Empty;
            this.lbl_weishengsuB1.Text = string.Empty;
            this.lbl_weishengsuB2.Text = string.Empty;
            this.lbl_weishengsuC.Text = string.Empty;
            this.lbl_weishengsuE.Text = string.Empty;
            this.lbl_shihuangchundangliang.Text = string.Empty;
            this.lbl_nikesuan.Text = string.Empty;
            this.lbl_huluobosu.Text = string.Empty;
            this.lbl_gai.Text = string.Empty;
            this.lbl_ling.Text = string.Empty;
            this.lbl_jia.Text = string.Empty;
            this.lbl_na.Text = string.Empty;
            this.lbl_mei.Text = string.Empty;
            this.lbl_tie.Text = string.Empty;
            this.lbl_xin.Text = string.Empty;
            this.lbl_xi.Text = string.Empty;
            this.lbl_tong.Text = string.Empty;
            this.lbl_men.Text = string.Empty;
            this.lbl_dian.Text = string.Empty;
        }
        /// <summary>
        /// 清理食物界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ButClear_Raw_Click(object sender, EventArgs e)
        {
            this.txtShiWumc.Text = "";

            this.txtGongYong.Text = "";
            dt.Clear();

            this.txt_reliang.Text = string.Empty;
            this.txt_danbaizhi.Text = string.Empty;
            this.txt_zhifang.Text = string.Empty;
            this.txt_huahewu.Text = string.Empty;
            this.txt_xianwei.Text = string.Empty;
            this.txt_Va.Text = string.Empty;
            this.txt_Vb1.Text = string.Empty;
            this.txt_Vb2.Text = string.Empty;
            this.txt_Vc.Text = string.Empty;
            this.txt_Ve.Text = string.Empty;
            this.txt_dangliang.Text = string.Empty;
            this.txt_nikesuan.Text = string.Empty;
            this.txt_luobu.Text = string.Empty;
            this.txt_gai.Text = string.Empty;
            this.txt_lin.Text = string.Empty;
            this.txt_jia.Text = string.Empty;
            this.txt_na.Text = string.Empty;
            this.txt_mei.Text = string.Empty;
            this.txt_tie.Text = string.Empty;
            this.txt_xin.Text = string.Empty;
            this.txt_xi.Text = string.Empty;
            this.txt_tong.Text = string.Empty;
            this.txt_meng.Text = string.Empty;
            this.txt_dian.Text = string.Empty;
        }
        #endregion

        #region 保存食物
        /// <summary>
        /// 保存食物信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void But_Raw_Click(object sender, EventArgs e)
        {
            int i = SetRawToDatabase();
            SetElementToDatabase(i);
        }

        public Int32 SetRawToDatabase()
        {
            TreeNode tn = this.Tv_RawMaterial2.SelectedNode;

            Catering_Model.E_RawMaterial cnrm = new Catering_Model.E_RawMaterial();
            Catering_Rules.T_RawMaterial crrm = new Catering_Rules.T_RawMaterial();
            int i = crrm.GetMaxId();
            cnrm.id = i;
            cnrm.RAWName = txtShiWumc.Text.Trim();
            cnrm.RAWTID = 1;
            cnrm.RAWID = Convert.ToInt32(this.DDLzhongsu.SelectedValue);
            cnrm.RAWIDS = Convert.ToInt32(this.DDLzhongsumin.SelectedValue);
            cnrm.RAWSid = DDLShiBu.SelectedValue;
            cnrm.RAWWid = DDLShuiFen.SelectedValue;
            cnrm.InDBid = "1";
            cnrm.RAWZS = Convert.ToInt32(DDLzhongsu.SelectedValue);
            cnrm.temp1 = this.txtzhesun.Text.Trim();
            crrm.Add(cnrm);
            return i;
        }
        /// <summary>
        /// 食物营养元素添加到数据库
        /// </summary>
        public void SetElementToDatabase(int i)
        {
            #region 将食物信息添加到数据库
            Txt_Xianwei(i);
            Txt_VA(i);
            Txt_Gai(i);
            #endregion
        }

        #region 将食物信息添加到数据库

        #region 营养素含量
        public void Txt_Xianwei(int i)
        {
            InsertNutrient("1", "热量", i);
            InsertNutrient("1", "蛋白质", i);
            InsertNutrient("1", "脂肪", i);
            InsertNutrient("1", "碳水化合物", i);
            InsertNutrient("1", "膳食纤维", i);
        }
        #endregion

        #region 维生素
        public void Txt_VA(int i)
        {
            InsertNutrient("2", "维生素A", i);
            InsertNutrient("2", "维生素B1", i);
            InsertNutrient("2", "维生素B2", i);
            InsertNutrient("2", "维生素C", i);
            InsertNutrient("2", "维生素E", i);
            InsertNutrient("2", "视黄醇当量", i);
            InsertNutrient("2", "尼克酸", i);
            InsertNutrient("2", "胡萝卜素", i);

        }
        #endregion

        #region 矿物质
        public void InsertNutrient(string strType, string strNurient, int i)
        {
            View_Operaction_Common voc = new View_Operaction_Common();
            Catering_Model.NutrientComposition cmnc = new Catering_Model.NutrientComposition();
            Catering_Rules.NutrientComposition crnc = new Catering_Rules.NutrientComposition();
            cmnc.id = crnc.GetMaxId() + 1;
            cmnc.RawID = i;
            cmnc.NutritionElementsID = Convert.ToInt32(voc.GetRawElement(strType, strNurient));
            cmnc.Content = this.txt_gai.Text.Trim();
            crnc.Add(cmnc);
        }
        public void Txt_Gai(int i)
        {
            InsertNutrient("3", "钙", i);
            InsertNutrient("3", "磷", i);
            InsertNutrient("3", "钾", i);
            InsertNutrient("3", "镁", i);
            InsertNutrient("3", "铁", i);
            InsertNutrient("3", "锌", i);
            InsertNutrient("3", "硒", i);
            InsertNutrient("3", "铜", i);
            InsertNutrient("3", "锰", i);
            InsertNutrient("3", "碘", i);
        }
        #endregion
        #endregion
        #endregion

        #region 原料种类添加

        public void butRawS_Click(string str)
        {

            string[] TypeName = str.Split(new char[] { ',' });
            Catering_Model.E_RawMaterials[] modes = new Catering_Model.E_RawMaterials[TypeName.Length];

            for (int i = 0; i < TypeName.Length; i++)
            {
                if (TypeName[i] != "" && TypeName[i] != null)
                {
                    Catering_Model.E_RawMaterials cmrm = new Catering_Model.E_RawMaterials();
                    cmrm.id = crrm.GetMaxId();
                    cmrm.TypeName = TypeName[i];
                    cmrm.Back = "";
                    cmrm.temp1 = "";
                    cmrm.temp2 = "";
                    modes[i] = cmrm;
                }
            }
            crrm.Add(modes);
        }
        #endregion
        #region 菜品种类添加

        public void butDishS_Click(string str)
        {

            string[] TypeName = str.Split(new char[] { ',' });
            Catering_Model.DishType[] modes = new Catering_Model.DishType[TypeName.Length];

            for (int i = 0; i < TypeName.Length; i++)
            {
                if (TypeName[i] != "" && TypeName[i] != null)
                {
                    Catering_Model.DishType cmrm = new Catering_Model.DishType();
                    cmrm.id = crdt.GetMaxId();
                    cmrm.DT = TypeName[i];
                    cmrm.Back = "";
                    cmrm.temp1 = "";
                    cmrm.temp2 = "";
                    modes[i] = cmrm;
                }
            }
            crdt.Add(modes);
        }
        #endregion

        protected void Dr_library_SelectedIndexChanged(object sender, EventArgs e)
        {
            voc.DropDownListDataBind_DishTypes(Dr_DishType, this.Dr_library.SelectedValue);
        }
        protected void DDLzhongsu_SelectedIndexChanged(object sender, EventArgs e)
        {
            voc.DropDownListDataBind_RawMaterialsInfo(DDLzhongsumin, DDLzhongsu.SelectedValue);
        }
        #endregion
        #region 菜谱设置
        protected void select_sihpu_click(object sender, EventArgs e)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("AreaID=" + this.Dr_Operaction.SelectedValue);
            sb.Append("   and ClassIDs=" + this.Dr_Class.SelectedValue);
            sb.Append("   and Back like'" + this.dr_year.SelectedValue + "-" + this.dr_Moth.SelectedValue + "%'");
            Catering_Rules.T_Recipes crr = new Catering_Rules.T_Recipes();
            DataSet ds = crr.GetList(sb.ToString());
            if (ds != null && ds.Tables.Count > 0)
            {
                System.Text.StringBuilder sbs = new System.Text.StringBuilder();
                foreach (DataRow dr in ds.Tables[0].Rows)
                {

                    sbs.Append(" <tr>");
                    sbs.Append(" <td class=\"xh_td\">" + dr["id"] + "</td>");
                    sbs.Append("<td>" + dr["CateringName"] + " </td>");
                    sbs.Append("<td>" + dr["temp2"] + " </td>");
                    sbs.Append("<td>" + dr["Back"] + " </td>");
                    sbs.Append("<td>" + GetAVGOld(dr["GroupID"].ToString()) + " </td>");
                    sbs.Append(" <td>  <a href=\"#\"><img src=\"../../Images/file.gif\" /></a> </td>");
                    sbs.Append("  <td align=\"center\"><a href=\"#\">  <img src=\"../../Images/trash.gif\" onclick=\" Del_set_shipu(" + dr["id"] + ")\"/></a></td>");
                    sbs.Append(" <tr>");


                }
                ViewState["showshipulist"] = sbs.ToString();
            }


        }
        private int GetAVGOld(string strRecipesID)
        {
            Catering_Rules.GroupCatering crgc = new Catering_Rules.GroupCatering();
            Catering_Model.GroupCatering cmgc = crgc.GetModel(Convert.ToInt32(strRecipesID));
            return (cmgc.MOld + cmgc.Wold) / 2;
        }
        protected void Dr_Operaction_SelectedIndexChanged(object sender, EventArgs e)
        {
            voc.DropDownListDataBind_Class(Dr_Class, Dr_Operaction.SelectedValue);
        }
        #endregion
    }
}
